package com.demo.user.feign;

import com.demo.common.base.pojo.JsonRes;
import com.demo.user.bo.CreateUserBO;
import com.demo.user.bo.UserMainPageBO;
import com.demo.user.converter.UserMainConverter;
import com.demo.user.entity.UserMain;
import com.demo.user.service.UserMainService;
import com.demo.user.vo.UserMainVO;
import com.mybatisflex.core.paginate.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 用户管理接口
 *
 * @author DayDayUp
 * create on 2023-05-18
 **/
@Slf4j
@RestController
@RequestMapping("userMain")
public class UseMainFeignClient {
    @Resource
    private UserMainService userMainService;
    @Resource
    private UserMainConverter userMainConverter;


    /**
     * 分页查询用户
     *
     * @param userMainPageBO 分页参数
     * @return JsonRes
     */
    @GetMapping("pageUserMain")
    public JsonRes<Page<UserMainVO>> pageUserMain(UserMainPageBO userMainPageBO) {
        log.info("UseMainFeignClient-pageUserMain");
        Page<UserMainVO> userMainVOPage = userMainService.pageUserMain(userMainPageBO);
        return JsonRes.ok(userMainVOPage);
    }

    @PostMapping("createUser")
    public JsonRes<Void> createUser(@RequestBody CreateUserBO createUserBO) {
        UserMain userMain = userMainConverter.toUserMain(createUserBO);
        userMainService.save(userMain);
        return JsonRes.ok();
    }

    @PostMapping("createUser1")
    public JsonRes<Void> createUser1(@RequestBody CreateUserBO createUserBO) {
        UserMain userMain = userMainConverter.toUserMain(createUserBO);
        userMainService.save(userMain);
//        System.out.println(1/0);
        return JsonRes.ok();
    }
}
